package com.manager;

import java.sql.Connection;
import java.sql.SQLException;

import com.mchange.v2.c3p0.C3P0Registry;
import com.mchange.v2.c3p0.ComboPooledDataSource;

import exceptions.InvalidArgumentException;

public class PoolDataSource {
	private static PoolDataSource poolDataSource = new PoolDataSource();

	public static final String REPORTES = "REPORTES";

	public static final String CEREUS = "CEREUS";

	private PoolDataSource() {
		new ComboPooledDataSource(CEREUS);
		new ComboPooledDataSource(REPORTES);
	}

	public static PoolDataSource getInstance() {
		return poolDataSource;
	}

	public Connection getConection(String dataSourceName) throws SQLException, InvalidArgumentException {
		ComboPooledDataSource comboPooledDataSource = (ComboPooledDataSource) C3P0Registry
				.pooledDataSourceByName(dataSourceName);
		if (comboPooledDataSource == null)
			throw new InvalidArgumentException(
					"El DataSource con Nombre= " + dataSourceName +" NO EXISTE");
		return comboPooledDataSource.getConnection();

	}
}